package com.qdlc.p2p.biz.web.filter;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

/**
 * struts2自带的文件上传过滤器会过滤掉百度编辑器，如果图片上传，不经过Struts过滤器  
 * 
 * @ClassName: RdStrutsFilter
 * @Description:
 * @author fuxingxing somesky.cn@gmail.com
 * @date 2013-7-17 上午9:15:49
 */
public class RdStrutsFilter extends StrutsPrepareAndExecuteFilter {
	
	private static Set<String> notNeedCheckUrls = new HashSet<String>();
	static{
		notNeedCheckUrls.add("/imageUp.jsp");
		notNeedCheckUrls.add("/upfile.jsp");
		notNeedCheckUrls.add("/plugins/ueditor/jsp/controller.jsp");
	}
	
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
		ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		String url = request.getRequestURI();
		if (notNeedCheckUrls.contains(url)) {
			chain.doFilter(req, res);
		} else {
			super.doFilter(req, res, chain);
		}
	}
}
